package org.yzh.web.business;

import com.alibaba.fastjson.JSONObject;
import io.github.yezhihao.netmc.session.Session;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.yzh.protocol.t808.*;
import org.yzh.web.business.kafka.kafkaDTO.Position4kafka;
import org.yzh.web.business.kafka.producer.Producer4Kafka;
import org.yzh.web.endpoint.MessageManager;

import javax.annotation.Resource;
import java.util.List;

/**
 * 业务处理 服务类
 * -1 2011协议版本
 * 0 2013
 * 1 2019
 */
@Component
public class GatewayService {

    @Resource
    private Producer4Kafka producer4Kafka;

    @Autowired
    private MessageManager messageManager;


    /**
     * 位置信息汇报
     * 1. push to  kafka
     */
    public void positionReport_200(List<T0200> list) {
        for (T0200 t0200 : list) {
            String jsonString = JSONObject.toJSONString(new Position4kafka(t0200));
            producer4Kafka.sendAsync(Producer4Kafka.TOPIC_NAME, jsonString);
        }
    }

    public T8100 register(T0100 message, Session session, T8100 response) {
        // 业务处理
        // 1.查询 redis的平台设备信息中 是否存在该车
        boolean flag = true;
        if (!flag) {
            response.setResultCode(T8100.NotFoundVehicle);
        }
        //messageManager.
        return response;
    }

    public T0001 authentication(T0102 message, Session session, T0001 response) {


        return response;
    }
}
